package com.xcdh.trading.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.trading.entity.HotMoneyInfo;
import com.xcdh.trading.entity.HotMoneyTrc;
import com.xcdh.trading.mapper.HotMoneyInfoMapper;
import com.xcdh.trading.response.TradingRes;
import com.xcdh.trading.service.HotMoneyInfoService;
import com.xcdh.trading.util.TuShareApi;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotMoneyInfoServiceImpl extends ServiceImpl<HotMoneyInfoMapper, HotMoneyInfo> implements HotMoneyInfoService {
    // 可以在这里实现额外的业务方法

    @Override
    public void syncHotMoneyInfo() {
        TradingRes tradingRes = TuShareApi.post("hm_list");
        List<HotMoneyInfo> hotMoneyInfos = tradingRes.parse(HotMoneyInfo.class);
        for (HotMoneyInfo hotMoneyInfo : hotMoneyInfos) {
            HotMoneyInfo info = lambdaQuery().eq(HotMoneyInfo::getName, hotMoneyInfo.getName()).one();
            if(info == null){
                save(hotMoneyInfo) ;
            }else {
                updateById(hotMoneyInfo) ;
            }
        }
    }
}
